﻿using System;
using System.Globalization;
using System.Linq;
using System.ServiceModel;
using System.Web;

using SBPweb.PlAzureNet.Shared.Library.Constants;

namespace SBPweb.PlAzureNet.Server.Library.Base
{

    public abstract class ServiceContractBase
    {

        public static CultureInfo GetCurrentContextCulture()
        {
            if (OperationContext.Current != null)
            {
                try
                {
                    string culture = OperationContext.Current.IncomingMessageHeaders.GetHeader<string>("culture", Namespaces.Services_Headers_Culture);
                    if (!string.IsNullOrEmpty(culture))
                    {
                        return CultureInfo.GetCultureInfo(culture);
                    }
                }
                catch
                {
                }
            }
            if (HttpContext.Current == null || HttpContext.Current.Request.UserLanguages == null)
            {
                return CultureInfo.CurrentCulture;
            }
            return CultureInfo.GetCultureInfo(HttpContext.Current.Request.UserLanguages.FirstOrDefault());
        }

    }

}